<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>${message("admin.scheme.edit")} - 766 SMART HOME</title>
<meta name="author" content="BIZ Team" />
<meta name="copyright" content="BIZ" />
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<link href="${base}/resources/admin/css/common.css" rel="stylesheet" type="text/css" />
<link href="${base}/resources/admin/css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
	<div class="path">
		<a href="${base}/admin/common/index.jhtml">${message("admin.path.index")}</a> &raquo; ${message("admin.scheme.edit")}
	</div>
	<form id="inputForm" action="update.jhtml" method="post" enctype="multipart/form-data">
		<ul id="tab" class="tab">
			<li>
				<input type="button" value="基本信息" />
			</li>
			<li>
				<input type="button" value="方案描述" />
			</li>
			<li>
				<input type="button" value="方案配置参数" />
			</li>
			<li>
				<input type="button" value="设备配置表" />
			</li>
			<li>
				<input type="button" value="方案辅材" />
			</li>
			<li>
				<input type="button" value="方案图片" />
			</li>
		</ul>
		<input type="hidden" id="id" name="id" value="${scheme.id}"/>
		<input type="hidden" id="hiddenPIds" name="spIds" value="${schemeProductIds}"/>
		<input type="hidden" id="hiddenAttrs" value="${scheme.attribute}"/>
		<table class="input tabContent">
			<tr>
				<th>
					<span class="requiredField">*</span>类型:
				</th>
				<td>
					<select id="type" name="type" class="option" value="${scheme.type}">
						<option value="">请选择</option>
						[#list types as type]
							<option value="${type.id}" [#if type.id == scheme.type]selected="selected"[/#if]>${type.title}</option>
						[/#list]
					</select>
				</td>
			</tr>
			<tr>
				<th>
					<span class="requiredField">*</span>分类:
				</th>
				<td>
					<select name="category" class="option" value="${scheme.category}">
						<option value="">请选择</option>
						[#list categorys as cat]
							<option value="${cat.id}" [#if cat.id == scheme.category]selected="selected"[/#if]>${cat.title}</option>
						[/#list]
					</select>
				</td>
			</tr>
			<tr>
				<th>
					<span class="requiredField">*</span>方案名称:
				</th>
				<td>
					<input type="text" name="name" class="text" maxlength="200" value="${scheme.name}"/>
				</td>
			</tr>
			<tr>
				<th>
					&nbsp;
				</th>
				<td>
					<a href="javascript:;" class="iconButton">
						<span class="addIcon">&nbsp;</span>选择主材产品
					</a>
				</td>
			</tr>
			<tr>
				<th>
					<span class="requiredField">*</span>主材产品:
				</th>
				<td>
					<!--方案主材产品位置-->
					<table class="input" id="schemeProductTable">
						[#if scheme.schemeProducts.size() > 0]
							<tr>
								<td width="40%;">主材名称</td>
								<td>主材品牌</td>
								<td>主材规格</td>
								<td>主材分类</td>
								<td>主材价格</td>
							</tr>
							[#list scheme.schemeProducts as schemeP]
								<tr>
									<td title="${schemeP.name}">${abbreviate(schemeP.name, 60, "...")}</td>
									<td>${schemeP.brand.name}</td>
									<td>${schemeP.specificationValue.name}</td>
									<td>${schemeP.category.title}</td>
									<td>${schemeP.price?string("0.00")}</td>
								</tr>
							[/#list]
						[/#if]
					</table>
				</td>
			</tr>
			<tr>
				<th>
					<span class="requiredField"></span>内机数量:
				</th>
				<td>
					<input type="text" name="inNumber" value="${scheme.inNumber}" class="text"/><span>&nbsp;&nbsp;[用于空调方案内机数量统计,非空调方案可不填写]</span>
				</td>
			</tr>
			<tr>
				<th>
					<span class="requiredField">*</span>方案属性:
				</th>
				<td>
					[#list schAttrs as schattr]
						<label><input type="checkbox" name="schemeAttr" value="${schattr.id}" />${schattr.title}</label>
					[/#list]
				</td>
			</tr>
			<tr>
				<th>
					<span class="requiredField">*</span>面积范围:
				</th>
				<td>
					[#list areaTags as at]
						<label><input type="radio" name="areaTag" value="${at.id}" [#if scheme.areaTag == at.id]checked="checked"[/#if]/>${at.title}</label>
					[/#list]
				</td>
			</tr>
			<tr>
				<th>
					<span class="requiredField">*</span>适用面积(㎡):
				</th>
				<td>
					<input type="text" name="beginArea" value="${scheme.beginArea}" class="text" maxlength="8" />
					-
					<input type="text" name="endArea" value="${scheme.endArea}" class="text" maxlength="8" />
				</td>
			</tr>
			<tr>
				<th>
					<span class="requiredField">*</span>辅材单价:
				</th>
				<td>
					<input type="text" name="auxiliaryUnitPrice" value="${scheme.auxiliaryUnitPrice}" class="text" maxlength="16" />(元/每平方米)
				</td>
			</tr>
			<tr>
				<th>
					<span class="requiredField">*</span>安装费:
				</th>
				<td>
					<input type="text" name="installCost" value="${scheme.installCost}" class="text" maxlength="16" />(元/每平方米)
				</td>
			</tr>
			<tr>
				<th>
					<span class="requiredField">*</span>方案面积(㎡):
				</th>
				<td>
					<input type="text" name="acreage" value="${scheme.acreage}" class="text" maxlength="16" />
				</td>
			</tr>
			<tr>
				<th>
					<span class="requiredField">*</span>展示图片:
				</th>
				<td>
					<span class="fieldSet">
						<input type="text" name="image" value="${scheme.image}" class="text" readonly="true" maxlength="200" title="用于首页方案的图片展示" />
						<input type="button" id="browserButton" class="button" value="${message("admin.browser.select")}" />
					</span>
					<span>
						[#if scheme.image != null]
							<a href="${scheme.image}" target="_blank">[查看图片]</a>
						[/#if]
					</span>
				</td>
			</tr>
			<tr>
				<th>
					上架时间:
				</th>
				<td>
					<input type="text" name="upDate" class="text Wdate" value="${scheme.upDate}"  onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'%y-%M-%d'})"/>
				</td>
			</tr> 
			<tr>
				<th>
					下架时间:
				</th>
				<td>
					<input type="text" name="downDate" class="text Wdate" value="${scheme.downDate}" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'%y-%M-%d'})"/>
				</td>
			</tr> 
			<tr>
				<th>
					设置:
				</th>
				<td>
					<label>
						<input type="checkbox" name="isMarketable" [#if scheme.isMarketable]checked="checked"[/#if] />${message("Product.isMarketable")}
					</label>
					<label>
						<input type="checkbox" name="isList" [#if scheme.isList] checked="checked"[/#if] />${message("Product.isList")}
					</label>
					<label>
						<input type="checkbox" name="isTop" [#if scheme.isTop]checked="checked"[/#if]/>${message("Product.isTop")}
					</label>
					<label>
						<input type="checkbox" name="isChange" [#if scheme.isChange]checked="checked"[/#if]/>固定方案
					</label>
					<label>
						<input type="checkbox" name="isTehui" [#if scheme.isTehui]checked="checked"[/#if]/>特惠活动
					</label>
				</td>
			</tr>
			<tr id="thTitleTr">
				<th>特惠标题:</th>
				<td><input type="text" class="text" name="tehuiTitle" value="${scheme.tehuiTitle}"></td>
			</tr>
			<tr>
				<th>
					搜索关键词:
				</th>
				<td>
					<input type="text" name="keyword" value="${scheme.keyword}" class="text" maxlength="200" title="${message("admin.product.keywordTitle")}" />
				</td>
			</tr>
			<tr>
				<th>
					页面标题:
				</th>
				<td>
					<input type="text" name="seoTitle" value="${scheme.seoTitle}" class="text" maxlength="200" />
				</td>
			</tr>
			<tr>
				<th>
					价格说明:
				</th>
				<td>
					<textarea name="priceDescript" class="text" maxlength="500" colspan="2">${scheme.priceDescript}</textarea>
				</td>
			</tr>
		</table>
		<table class="input tabContent">
			<tr>
				<td>
					<textarea id="editor" name="introduction" class="editor" style="width: 100%;">${scheme.introduction}</textarea>
				</td>
			</tr>
		</table>
		<table id="productImageTable" class="input tabContent">
			<tr>
				<td>
					<textarea id="editor1" name="parameter" class="editor" style="width: 100%;">${scheme.parameter}</textarea>
				</td>
			</tr>
		</table>
		<table class="input tabContent">
			<tr>
				<td>
					<textarea id="editor2" name="configuration" class="editor" style="width: 100%;">${scheme.configuration}</textarea>
				</td>
			</tr>
		</table>
		<table class="input tabContent">
			<tr>
				<td>
					<textarea id="editor3" name="auxiliaryDescript" class="editor" style="width: 100%;">${scheme.auxiliaryDescript}</textarea>
				</td>
			</tr>
		</table>
		<table class="input tabContent" id="productImageTable">
			<thead>
				<tr>
					<td colspan="4">
						<a href="javascript:;" id="addProductImage" class="button">添加方案图片</a>
					</td>
				</tr>
				<tr class="title">
					<td>文件</td>
					<td>标题</td>
					<td>排序</td>
					<td>删除</td>
				</tr>
			</thead>
			<tbody id="schemeProductImageBody">
				[#list scheme.schemeImages as schemeImage]
					<tr class='spImageTr'>
						<td>
							<input type="hidden" name="schemeImages[${schemeImage_index}].source" value="${schemeImage.source}" />
							<input type="hidden" name="schemeImages[${schemeImage_index}].large" value="${schemeImage.large}" />
							<input type="hidden" name="schemeImages[${schemeImage_index}].medium" value="${schemeImage.medium}" />
							<input type="hidden" name="schemeImages[${schemeImage_index}].thumbnail" value="${schemeImage.thumbnail}" />
							<input type="file" name="schemeImages[${schemeImage_index}].file" class="schemeImageFile ignore" />
							<a href="${schemeImage.large}" target="_blank">${message("admin.common.view")}</a>
						</td>
						<td>
							<input type="text" name="schemeImages[${schemeImage_index}].title" class="text" maxlength="200" value="${schemeImage.title}" />
						</td>
						<td>
							<input type="text" name="schemeImages[${schemeImage_index}].order" class="text schemeImageOrder" value="${schemeImage.order}" maxlength="9" style="width: 50px;" />
						</td>
						<td>
							<a href="javascript:;" class="deleteProductImage">[删除]</a>
						</td>
					</tr>
				[/#list]
			</tbody>
		</table>
		<table class="input">
			<tr>
				<th>
					&nbsp;
				</th>
				<td>
					<input type="submit" class="button" value="${message("admin.common.submit")}" />
					<input type="button" class="button" value="${message("admin.common.back")}" onclick="window.location.href='list.jhtml'" />
				</td>
			</tr>
		</table>
	</form>
	<!--选择主材弹出层-->
	<div class="c-pop-window"  id="Check_See">
		<div class="c-pop-content" id="Check_See2s">
			<h2>选择主材产品</h2>
			<img src="${base}/resources/admin/images/x.png" onClick="colseSchemeProduct();">
			<div class="bar j-pop-bar">
				<span id="searchPropertySelect">&nbsp;</span>主材编码:
				<input type="text" class="text" style="width:120px;" id="querySn" name="querySn"/>
				<span id="searchPropertySelect">&nbsp;</span>主材名称:
				<input type="text" class="text" style="width:120px;" id="queryName" name="queryName"/>
				<input type="button" class="button" id="queryschemeproductBtn" value="查询"/>
			</div>
			<div class="c-scrollBox">
				<table class="baseTable-border" id="schemeproductTab">
					<thead>
						<tr>
							<th style="width:5%;">
								<span>&nbsp;</span>
							</th>
							<th style="width:15%;">
								<span>编码</span>
							</th>
							<th>
								<span>名称</span>
							</th>
							<th>
								<span>品牌</span>
							</th>
							<th>
								<span>规格</span>
							</th>
							<th>
								<span>分类</span>
							</th>
							<th>
								<span>价格</span>
							</th>
							<th width="80px;">
								<span>是否特惠</span>
							</th>
							<th width="80px;">
								<span>是否提点产品</span>
							</th>
						</tr>
					</thead>
					<tbody>
						
					</tbody>
				</table>
			</div>	
	      	<div style="text-align: center;">
	      		<a href="JavaScript:;" class="button ensure" onClick="sureProduct();">确定</a>
	      	</div>
	    </div>
		<div class="c-cover"></div>
	</div>
</body>
</html>
<script type="text/javascript" src="${base}/resources/admin/js/jquery.js"></script>
<script type="text/javascript" src="${base}/resources/admin/js/jquery.tools.js"></script>
<script type="text/javascript" src="${base}/resources/admin/js/jquery.validate.js"></script>
<script type="text/javascript" src="${base}/resources/admin/editor/kindeditor.js"></script>
<script type="text/javascript" src="${base}/resources/admin/js/common.js"></script>
<script type="text/javascript" src="${base}/resources/admin/js/input.js"></script>
<script type="text/javascript" src="${base}/resources/admin/editor/customeditor.js"></script>
<script type="text/javascript" src="${base}/resources/admin/js/scheme.js"></script>
<script type="text/javascript" src="${base}/resources/admin/datePicker/WdatePicker.js"></script>

<script type="text/javascript">
	$().ready(function() {
	
		[@flash_message /]
		
		var $inputForm = $("#inputForm");
		var $addProductImage = $("#addProductImage");
		var $deleteProductImage = $("a.deleteProductImage");
		var $browserButton = $("#browserButton");
		var $schemeType =$("select[name='type']");
		var $schemeProduct = $("select[name='schemeProduct']");
		var $selectProduct = $("#Check_See");
		var $schemeproductTab = $("#schemeproductTab");
		var $productImageTable = $("#productImageTable");
		var $schemeProductImageBody =$("#schemeProductImageBody");
		var $addConstructImage = $("#addConstructImage");
		var $constructImageBody = $("#constructImageBody");
		var $deleteConstructImage = $("a.deleteConstructImage");
		var $type = $("#type");
		var $category = $("select[name='category']");
		var $queryschemeproductBtn = $("#queryschemeproductBtn");
		var $isTehui = $("input[name='isTehui']");
		var $thTitleTr = $("#thTitleTr");
		
		//选中勾选的复选框标签
		var attrs = new Array();
		var attr = $("#hiddenAttrs").val();
		var attrBox = $("input[name='schemeAttr']");
		//选择被勾选的属性标签
		if(attr != null && attr != ""){
			attrs = attr.split(",");
			for(var i = 0;i<attrBox.length;i++){
				for(var j= 0 ;j<attrs.length;j++){
					if(attrs[j] == attrBox[i].value){
						attrBox[i].checked='checked';
						break;
					}
				}
			}
		}
		
		$browserButton.browser();
		
		//特惠
		checkTehui();
		
		$isTehui.change(function(){
			checkTehui();
		});
		
		function checkTehui(){
			var checkVal = $isTehui.is(":checked");
			if(checkVal){
				$thTitleTr.show();
			}else{
				$thTitleTr.hide();
			}
		}
		
		//类型更换查询分类
		$type.change(function(){
			var type = $("select[name='type']").val();
			if(type == null || type == ""){
				$category.empty();
				$category.append("<option value=''>请选择</option>");
			}else{
				findSchemeCategoryByType(type,'${base}');
			}
		});
		
		$(".iconButton").click(function(){
			//判断是否选择了类型
			var category = $category.val();
			if(category == null || category == ""){
				$.message("warn","请选择方案分类！");
				return false;
			}else{
				var pIds = $("#hiddenPIds").val().split(",");
				findSchemeProduct(category,'${base}','','',pIds);
			}
		});
		
		//主材查询
		$queryschemeproductBtn.click(function(){
			//判断是否选择了类型
			var type = $category.val();
			var sn = $("#querySn").val();
			var name = $("#queryName").val();
			if(type == null || type == ""){
				$.message("warn","请先选择方案分类！");
				return false;
			}else{
				findSchemeProduct(type,'${base}',sn,name);
			}
		});
		
		// 增加方案图片
		$addProductImage.click(function() {
			//获取已存在tr长度
			var trlength = $schemeProductImageBody.find(".spImageTr").length;
			var trHtml = "<tr class='spImageTr'>";
				trHtml += "<td><input type='file' name='schemeImages["+trlength+"].file' class='productImageFile' /></td>";
				trHtml += "<td><input type='text' name='schemeImages["+trlength+"].title' class='text' maxlength='200'/></td>";
				trHtml += "<td><input type='text' name='schemeImages["+trlength+"].order' class='text productImageOrder' maxlength='9' style='width: 50px;'/></td>";
				trHtml += "<td><a href='javascript:;' class='deleteProductImage'>[删除]</a></td>";
				trHtml += "</tr>";
			$("#schemeProductImageBody").append(trHtml);
		});
		
		//添加施工图片
		$addConstructImage.click(function(){
			//获取已存在tr长度
			var trlen = $constructImageBody.find(".consImageTr").length;
			var trHtm = "<tr class='consImageTr'>";
				trHtm += "<td><input type='file' name='constructImages["+trlen+"].file' class='productImageFile' /></td>";
				trHtm += "<td><input type='text' name='constructImages["+trlen+"].title' class='text' maxlength='200'/></td>";
				trHtm += "<td><input type='text' name='constructImages["+trlen+"].order' class='text productImageOrder' maxlength='9' style='width: 50px;'/></td>";
				trHtm += "<td><a href='javascript:;' class='deleteConstructImage'>[删除]</a></td>";
				trHtm += "</tr>";
			$constructImageBody.append(trHtm);
		});
		
		// 删除方案图片
		$deleteProductImage.live("click", function() {
			var $this = $(this);
			$.dialog({
				type: "warn",
				content: "${message("admin.dialog.deleteConfirm")}",
				onOk: function() {
					$this.closest("tr").remove();
				}
			});
		});
		
		// 删除施工图片
		$deleteConstructImage.live("click", function() {
			var $this = $(this);
			$.dialog({
				type: "warn",
				content: "${message("admin.dialog.deleteConfirm")}",
				onOk: function() {
					$this.closest("tr").remove();
				}
			});
		});
		
		// 表单验证
		$inputForm.validate({
			rules: {
				type: "required",
				name: "required",
				schemeAttr: "required",
				areaTag: "required",
				beginArea: {
					required: true,
					pattern:/^[0-9]*$/,
					maxlength:8,
					minlength:1
				},
				endArea: {
					required: true,
					pattern:/^\+?[1-9][0-9]*$/,
					maxlength:8,
					minlength:1
				},
				acreage: {
					required: true,
					pattern:/^[0-9]*$/,
					maxlength:12,
					minlength:1
				},
				auxiliaryUnitPrice:{
					required: true,
					pattern:/^(?!00)(?!0.$)(?!0.0$)(?!0.00$)[0-9]+[.]?[0-9]{0,2}$/,
					maxlength:12,
					minlength:1
				},
				installCost:{
					required: true,
					pattern:/^(?!00)(?!0.$)(?!0.0$)(?!0.00$)[0-9]+[.]?[0-9]{0,2}$/,
					maxlength:12,
					minlength:1
				},
				image: "required"
			},
			messages: {
				name: {
					required: "${message("admin.validate.required")}",
				},
				type: {
					required: "${message("admin.validate.required")}",
				},
				beginArea: {
					required: "${message("admin.validate.required")}",
					pattern:"请输入整数适用面积值"
				},
				endArea: {
					required: "${message("admin.validate.required")}",
					pattern:"请输入整数适用面积值"
				},
				acreage: {
					required: "${message("admin.validate.required")}",
					pattern:"请输入整数格式的面积值"
				},
				auxiliaryUnitPrice: {
					required: "${message("admin.validate.required")}",
					pattern:"请输入正确格式的金额"
				},
				installCost: {
					required: "${message("admin.validate.required")}",
					pattern:"请输入正确格式的金额"
				},
				image: {
					required: "${message("admin.validate.required")}",
				}
			},
			submitHandler: function(form) {
				var pIds = $("#hiddenPIds").val();
				if(pIds == null || pIds == ""){
					$.message("warn","请选择主材产品");
					return false;
				}
				form.submit();
			}
		});
		
	});
	
</script>